package com.mindao.app.ued.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mindao.app.common.base.controller.BaseCoreController;
import com.mindao.app.ued.model.Tpltree1;

@Controller
@RequestMapping("/ued/tpltree1")
public class Tpltree1Controller extends BaseCoreController {
	private final Logger log = LoggerFactory.getLogger(Tpltree1Controller.class);
	@RequestMapping
	public String menu_list(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		rhs.addAttribute("tpltree1RootList", common_get_tree_root("Tpltree1"));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", "");
		return super.rtnDefault(request, response, session, rhs);
	}
	@RequestMapping
	public String create(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		String id = getpara("id");
		if ("root".equals(id)) {
			Tpltree1 tpltree1 = new Tpltree1();
			tpltree1.setName("");
			baseService.create(tpltree1);
		} else {
			Tpltree1 parent_org = (Tpltree1) baseService.loadById("Tpltree1",
					Long.parseLong(id));
			Tpltree1 subtpltree1 = new Tpltree1();
			subtpltree1.setName("");
			subtpltree1.setParentModel(parent_org);
			baseService.create(subtpltree1);
		}
		rhs.addAttribute("tpltree1RootList", common_get_tree_root(getpara("beanname")));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", " 添加新节点!");
		return super.rtnDefault(request, response, session, rhs);
	}	
	@RequestMapping
	public String update(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		try {
			common_update();
		} catch (Exception e) {
			rhs.addAttribute("info_type", "error");
			rhs.addAttribute("info", " 属性更新失败!");
			return "success";
		}
		rhs.addAttribute("tpltree1RootList", common_get_tree_root(getpara("beanname")));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", "更新成功!");
		return super.rtnDefault(request, response, session, rhs);
	}
	@Override
	@RequestMapping
	public String delete(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs,@RequestParam (required = false) String id) throws Exception {
		common_del_tree_node();
		rhs.addAttribute("tpltree1RootList", common_get_tree_root(getpara("beanname")));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", " 删除成功!");
		return super.rtnDefault(request, response, session, rhs);
	}
	@RequestMapping
	public String change_rank(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		common_change_rank(); 
		rhs.addAttribute("tpltree1RootList", common_get_tree_root(getpara("beanname")));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", "改变顺序成功!");
		return super.rtnDefault(request, response, session, rhs);
	}
	@RequestMapping
	public String change_level(HttpServletRequest request,HttpServletResponse response,HttpSession session,Model rhs) throws Exception {
		common_change_level();
		rhs.addAttribute("tpltree1RootList", common_get_tree_root(getpara("beanname")));
		rhs.addAttribute("info_type", "success");
		rhs.addAttribute("info", "改变层级成功!");
		return super.rtnDefault(request, response, session, rhs);
	}
}